//
// Created by guanyicheng on 2022/5/17.
//

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */

#include "../../common.h"

class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode *root) {
        vector<vector<int>> res{};
        if (root == nullptr) {
            return res;
        }
        deque<TreeNode *> que{};
        que.emplace_back(root);
        while (!que.empty()) {
            int size = que.size();
            auto v1 = vector<int>{};
            while (size-- > 0) {
                TreeNode *t = que.front();
                que.pop_front();
                v1.emplace_back(t->val);
                if (t->left) que.emplace_back(t->left);
                if (t->right) que.emplace_back(t->right);
            }
            res.emplace_back(v1);
        }
        return res;
    }
};

int main() {

    cout << Solution().levelOrder(nullptr).size() << endl;
}